#!/bin/bash

# java executable
JAVA=java
JAVA_OPT="-server"
#JAVA=/opt/IBMJava2-141/bin/java
#JAVA_OPT=
# -enableassertions

# jist directories
JIST_DIR=`dirname $0`/..
JIST_SRC=${JIST_DIR}/src
JIST_LIBS=${JIST_DIR}/libs/bcel.jar:${JIST_DIR}/libs/bsh.jar:${JIST_DIR}/libs/jargs.jar:${JIST_DIR}/libs/log4j.jar:${JIST_DIR}/libs/jython.jar
#JAVA_OPT="${JAVA_OPT} -Dlog4j.debug"

# .so path
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${JIST_SRC}/jist/swans/misc
export LD_LIBRARY_PATH

# max heap
MEM=`cat /proc/meminfo | grep MemTotal | grep -o "[0-9]\+"`
MEM=$(( ($MEM-200000)/1024 ))

# run spot, run
exec env CLASSPATH=${JIST_SRC}:${JIST_LIBS}:${CLASSPATH} ${JAVA} ${JAVA_OPT} -Xmx${MEM}m jist.runtime.Main ${JIST_ARGS} $*
